using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.Linq;
using System.Reflection;
namespace BehTree{
[Serializable]
    public class MyCondition : ISerializationCallbackReceiver
    {
        public void OnBeforeSerialize()
        {
            
        }

        public void OnAfterDeserialize()
        {
            
        }

        [SerializeField]
        public Component target;
        [SerializeField]
        public string methodName;// public abstract bool SingleDecide() ;
        public GameObject obj;
        public bool InvokeCondition()
        {
            MethodInfo mi;
            if (target != null && methodName != "" && obj != null)
            {
                mi = target.GetType().GetMethod(methodName);
                if(mi!=null&&mi.ReturnType==typeof(bool))
                {
                    return (bool)mi.Invoke(target,null);
                }
                return false;
            }
            else
                return true;
        }

    }
    [Serializable]
    public class CondEvent{
        [SerializeField]
        public List<MyCondition> conditions;
        public int Count=>conditions.Count;
        public CondEvent(){
            conditions=new List<MyCondition>();
        }
        public bool Invoke()
        {
            for(int i=0;i<conditions.Count;i++)
            {
                if(!conditions[i].InvokeCondition())
                    return false;
            }
            return true;
        }
    }
}